// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.IndexManagement;

public sealed partial class DataStreamLifecycleDownsampling
{
	/// <summary>
	/// <para>The list of downsampling rounds to execute as part of this downsampling configuration</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("rounds")]
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.DownsamplingRound> Rounds { get; set; }
}

public sealed partial class DataStreamLifecycleDownsamplingDescriptor : SerializableDescriptor<DataStreamLifecycleDownsamplingDescriptor>
{
	internal DataStreamLifecycleDownsamplingDescriptor(Action<DataStreamLifecycleDownsamplingDescriptor> configure) => configure.Invoke(this);

	public DataStreamLifecycleDownsamplingDescriptor() : base()
	{
	}

	private ICollection<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.DownsamplingRound> RoundsValue { get; set; }
	private DownsamplingRoundDescriptor RoundsDescriptor { get; set; }
	private Action<DownsamplingRoundDescriptor> RoundsDescriptorAction { get; set; }
	private Action<DownsamplingRoundDescriptor>[] RoundsDescriptorActions { get; set; }

	/// <summary>
	/// <para>The list of downsampling rounds to execute as part of this downsampling configuration</para>
	/// </summary>
	public DataStreamLifecycleDownsamplingDescriptor Rounds(ICollection<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.DownsamplingRound> rounds)
	{
		RoundsDescriptor = null;
		RoundsDescriptorAction = null;
		RoundsDescriptorActions = null;
		RoundsValue = rounds;
		return Self;
	}

	public DataStreamLifecycleDownsamplingDescriptor Rounds(DownsamplingRoundDescriptor descriptor)
	{
		RoundsValue = null;
		RoundsDescriptorAction = null;
		RoundsDescriptorActions = null;
		RoundsDescriptor = descriptor;
		return Self;
	}

	public DataStreamLifecycleDownsamplingDescriptor Rounds(Action<DownsamplingRoundDescriptor> configure)
	{
		RoundsValue = null;
		RoundsDescriptor = null;
		RoundsDescriptorActions = null;
		RoundsDescriptorAction = configure;
		return Self;
	}

	public DataStreamLifecycleDownsamplingDescriptor Rounds(params Action<DownsamplingRoundDescriptor>[] configure)
	{
		RoundsValue = null;
		RoundsDescriptor = null;
		RoundsDescriptorAction = null;
		RoundsDescriptorActions = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (RoundsDescriptor is not null)
		{
			writer.WritePropertyName("rounds");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, RoundsDescriptor, options);
			writer.WriteEndArray();
		}
		else if (RoundsDescriptorAction is not null)
		{
			writer.WritePropertyName("rounds");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new DownsamplingRoundDescriptor(RoundsDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (RoundsDescriptorActions is not null)
		{
			writer.WritePropertyName("rounds");
			writer.WriteStartArray();
			foreach (var action in RoundsDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new DownsamplingRoundDescriptor(action), options);
			}

			writer.WriteEndArray();
		}
		else
		{
			writer.WritePropertyName("rounds");
			JsonSerializer.Serialize(writer, RoundsValue, options);
		}

		writer.WriteEndObject();
	}
}